//==============================================================================
//
//               Copyright (C) 2003  Dick van Oudheusden
//  
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this library; if not, write to the Free
// Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
//==============================================================================
// 
//  $Date: 2003-12-04 21:30:42 $ $Revision: 1.1 $
//
//==============================================================================

#include <stdlib.h>

#include "ofc/config.h"

#include "ofc/DFraction.h"

#include "DInc.h"
#include "DTest.h"

//-DataTypes-------------------------------------------------------------------

void DFraction_test()
{
  DFraction *one =  [DFraction alloc];
  DFraction *two = [[DFraction alloc] init];
  
  STARTTEST();

  [one init :6 :4];
  
  TEST([one numerator  ] == 3);
  TEST([one denominator] == 2);

  TEST([two numerator  ] == 0);
  TEST([two denominator] == 1);

  [two numerator   :4 ];
  [two denominator :20];

  [one move :two];

  TEST([one numerator  ] == 1);
  TEST([one denominator] == 5);

  TEST([[[[one set :6 :4 ]  add :two] toText] icompare :"1 7/10" ] == 0);  
  TEST([[[[one set :6 :-4]  add :two] toText] icompare :"-1 3/10"] == 0);
  TEST([[[[one set :6 :4]   sub :two] toText] icompare :"1 3/10" ] == 0);
  TEST([[[[one set :-6 :-4] sub :two] toText] icompare :"1 3/10" ] == 0);
  TEST([[[[one set :6 :4]   mul :two] toText] icompare :"3/10"   ] == 0);
  TEST([[[[one set :-6 :4]  mul :two] toText] icompare :"-3/10"  ] == 0);  
  TEST([[[[one set :6 :4]   invert  ] toText] icompare :"2/3"    ] == 0);  
  TEST([[[[one set :6 :-4]  invert  ] toText] icompare :"-2/3"   ] == 0);
  TEST([[[[one set :6 :4]   div :two] toText] icompare :"7 1/2"  ] == 0);
  TEST([[[[one set :-6 :4]  div :two] toText] icompare :"-7 1/2" ] == 0);

  TEST([[one set :6 :4] toDouble] == 1.5);

  STOPTEST();

  [one free];
  [two free];
}

